package cn.com.lms.business.questionnaire.service;

import cn.com.lms.business.questionnaire.persistence.entity.UserQuestionnaireTitle;
import cn.com.lms.business.questionnaire.persistence.repository.UserQuestionnaireTitleRepository;


import com.bnzj.core.persistence.BaseService;
import com.bnzj.core.persistence.query.QueryHelpBean;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 16266
 * @DateTime: 2020/4/2 17:29
 * @Description: 用户问卷调查封面
 */
@Service
public class UserQuestionnaireTitleService extends BaseService<UserQuestionnaireTitleRepository, UserQuestionnaireTitle,Long> {

    public static QueryHelpBean getQueryHelpBean() {
        String selectSQL = "select  d.* ";
        String whereSQL = " from (SELECT a.id plan_id, a.plan_name, a.create_time,b.id stage_id, b.stage_name, d.user_id, d.stage_detail_id, e.id questionnaire_id, e.questionnaire_name , e.`status` FROM bnz_learning_plan a, bnz_learning_stage b, bnz_learning_stage_detail c, bnz_learning_student d, bnz_questionnaire_info e WHERE a.id = b.plan_id AND b.id = c.stage_id AND c.id = d.stage_detail_id AND a.id = d.plan_id AND c.obj_id = e.id AND c.study_type = '1' AND a.is_delete = '0' \n" +
                "\tAND b.is_delete = '0' AND e.`status` = 1 AND d.finish_state=0) d where 1=1 ";
        QueryHelpBean queryBean = new QueryHelpBean(selectSQL + whereSQL, "select count(1)" + whereSQL, UserQuestionnaireTitle.class);
        return queryBean;
    }

    public List<UserQuestionnaireTitle> findUserQuestionnaireTitle(Long userId) {
        return repository.findUserQuestionnaireTitle(userId);
    }
}
